import Vue from 'vue'
import Vuex from 'vuex'


Vue.use(Vuex);


const store = new Vuex.Store({
    state: {

        //项目id
        projectId: localStorage.getItem('projectId') || 0,

        //项目名
        projectName: localStorage.getItem('projectName') || '',

        //分组id
        apiGroupId: '',


        //分组
        apiGroup: [],

        //接口信息
        interfaceInfo: {}
    },

    mutations: {
        SET_PROJECTID: (state, projectId) => {
            state.projectId = projectId
                // sessionStorage.setItem('projectId', projectId)
            localStorage.setItem('projectId', projectId)
        },

        SET_PROJECTNAME: (state, projectName) => {
            state.projectName = projectName
            localStorage.setItem('projectName', projectName)
        },

        SET_APIGROUP: (state, apiGroup) => {
            state.apiGroup = apiGroup
            localStorage.setItem('apiGroup', apiGroup)
        },

        SET_INTERFACEINFO: (state, interfaceInfo) => {
            state.interfaceInfo = interfaceInfo
            localStorage.setItem('interfaceInfo', interfaceInfo)
        },

        //保存分组id
        SET_APIGROUPID: (state, apiGroupId) => {
            state.apiGroupId = apiGroupId
            localStorage.setItem('apiGroupId', apiGroupId)
        },



    },

    getters: {},
    actions: {
        addProjectId({ commit }, projectId) {
            commit('SET_PROJECTID', projectId)
        },

    }
})



export default store